Skip to content

An Exciting New World

Video Summary

In this lesson, we explore a few different loading strategies for an e-commerce app.

On the left, we have several different categories. By clicking different categories, we load a different subset of shoes. We get the category from the URL, which uses a dynamic segment, /shop/[categorySlug].

In a real app, this would involve a database query, but we're once again faking it in JS. This is unrealistically speedy, so I added an artificial delay:

export async function getShoesForCategory(category) {
await delay(2000);
return SHOES.filter((shoe) =>
shoe.categories.includes(category.toLowerCase())
);
}
const delay = (ms) =>
new Promise((resolve) => setTimeout(resolve, ms));

With this 2-second delay, the user experience is terrible; the user stares at a blank white screen while we wait for the shoes to load:

In this video, we explore two separate solutions in depth:

  1. The “classic” approach, using SWR
  2. A fancy new approach, using modern Next features and React Suspense

This isn't really the sort of video I know how to transcribe effectively. I strongly encourage you to watch the whole thing, to see how I implement the two different approaches, and to see the results!

Phew, we covered a lot of ground in that one! As I mentioned in the video, don't worry if you're feeling overwhelmed: we'll learn more about how all this stuff works in the lessons ahead.

(I also recognize that I have yet to actually define “Suspense” for you; I thought it would be helpful to start with the practical implications, but rest assured, we'll get to the theory shortly!)

You can see all of the code for this project on Github (opens in new tab). I've committed the final solution, using Suspense via loading.js, but you can see the alternative implementations in the /alternatives directory (opens in new tab).

We touch on a few different Next concepts in this project. You can learn more in the Next docs: